home *** CD-ROM | disk | FTP | other *** search
/ BBS Toolkit / BBS Toolkit.iso / rbbs_pc / mnt_201.zip / MAKELIST.C < prev    next >
Text File  |  1992-01-05  |  5KB  |  125 lines

  1. /****************************************************************************/
  2. /* MAKELIST module for RBBSMNT v2.01, a maintenance utility for RBBS-PC     */
  3. /*╒═════════════════════════════ NOTICE ═══════════════════════════════════╕*/
  4. /*│  A limited license is granted to all users of this program to make     │*/
  5. /*│  copies if this program and distribute those copies to other users     │*/
  6. /*│  on the following three conditions:                                    │*/
  7. /*│                                                                        │*/
  8. /*│    1.   This notice is NOT altered, bypassed or removed,               │*/
  9. /*│    2.   The program is not to be distributed to others in modified     │*/
  10. /*│         form. You may make changes for your own non-commercial use     │*/
  11. /*│    3.   No fee is to be charged (or any other consideration received)  │*/
  12. /*│         for copying or distributing these programs without an express  │*/
  13. /*│         written agreement with J. Terpstra, Bamestra RBBS, PO Box 66,  │*/
  14. /*│         Beemster, The Netherlands.                                     │*/
  15. /*│                                                                        │*/
  16. /*│Copyright (C) 1991, 1992 - Jan Terpstra, Bamestra RBBS, The Netherlands.│*/
  17. /*╘════════════════════════════════════════════════════════════════════════╛*/
  18. /****************************************************************************/
  19.  
  20. #include "rbbsmnt.h"                    /* definitions for this program     */
  21. #include "externs.h"                    /* external data references         */
  22.  
  23.   /**************************************************************************/
  24.   /* make a list of all messages                                            */
  25.   /**************************************************************************/
  26.  
  27. int makelist(int fp)
  28. {
  29.    int cur_rec;                         /* current record pos in msg file   */
  30.    int num_rec;                         /* # records in this messages       */
  31.    int year,month,day;                  /* timestamp                        */
  32.    long msgpos;
  33.    int xnum,count = 0;
  34.  
  35.    lives = 0;
  36.    deads = 0;
  37.    bads = FALSE;
  38.  
  39.    if (quiet)
  40.    {
  41.       printf("\r  Scanning msg file");
  42.    }
  43.    get_rbbs_hdr(fp);                    /* get the file header              */
  44.  
  45.    if (next_rec > first_rec)            /* any messages?                    */
  46.    {
  47.       cur_rec = first_rec;
  48.  
  49.       do
  50.       {
  51.          msgpos = (long)(cur_rec-1)*128L;
  52.          lseek(fp, msgpos, SEEK_SET);   /* move to start of message         */
  53.          read(fp, (char *)&msg_hdr, (size_t)sizeof(RBBSMSG));
  54.          cur_rec++;
  55.  
  56.          if (msg_hdr.enter_date[2] == '-' && msg_hdr.enter_date[5] == '-' &&
  57.          msg_hdr.enter_time[2] == ':')  /* got a real message header?       */
  58.          {
  59.             count++;
  60.             sscanf(msg_hdr.num_recs, "%4u", &num_rec);
  61.  
  62.             if (!strncmp(msg_hdr.msg_stat, ALIVE, 1))/* alive msg?          */
  63.             {
  64.                sscanf(msg_hdr.enter_date, "%2u-%2u-%2u", &month, &day, &year
  65.                );
  66.                mlist[lives].msg_age = (int)(now-(((year-80)*365)+to_month
  67.                [month-1]+day));
  68.                sscanf(msg_hdr.msg_number, "%4u", &xnum);
  69.                mlist[lives].old_num = xnum;
  70.                mlist[lives].new_num = mlist[lives].old_num;
  71.                mlist[lives].num_recs = num_rec;
  72.                mlist[lives].msg_pos = msgpos;
  73.                lives++;
  74.             }
  75.  
  76.             else
  77.             {
  78.                deads++;
  79.             }
  80.             cur_rec += num_rec-1;
  81.          }
  82.  
  83.          else
  84.          {
  85.  
  86.             /****************************************************************/
  87.             /* next record read wasn't a msg header!!!!                     */
  88.             /****************************************************************/
  89.  
  90.             bads = TRUE;
  91.  
  92.             while (cur_rec < last_rec)  /* search for a msg header          */
  93.             {
  94.                read(fp, (char *)&msg_hdr, (size_t)sizeof(RBBSMSG));
  95.  
  96.                if (msg_hdr.enter_date[2] == '-' && msg_hdr.enter_date[5] ==
  97.                '-' && msg_hdr.enter_time[2] == ':')/* got a real message
  98.                                            header?                          */
  99.                {
  100.                   sscanf(msg_hdr.msg_number, "%4u", &xnum);
  101.                   sprintf(logbuf, "Fixed broken link at msg %05d.", xnum);
  102.                   writelog(logbuf, 1, 1);
  103.                   msgpos = (long)(cur_rec-1)*128L;
  104.                   break;
  105.                }
  106.                cur_rec++;
  107.             }
  108.  
  109.             if (cur_rec >= next_rec)
  110.             {
  111.                sprintf(logbuf, "Fixed msg file corruption.");
  112.                writelog(logbuf, 1, 0);
  113.             }
  114.          }
  115.       }
  116.  
  117.       while (cur_rec < next_rec);
  118.    }
  119.    printf("\r\33[K");
  120.    sprintf(logbuf, "Found %05d active msgs.", lives);
  121.    writelog(logbuf, 1, 4);
  122.    return (count);
  123. }
  124.  
  125.